//
//  InSoundedFrame.m
//  Inner  Voice
//
//  Created by brother on 16/3/11.
//  Copyright © 2016年 徐海宇. All rights reserved.
//

#import "InSoundedFrame.h"

#import "InSoundDetail.h"

@implementation InSoundedFrame

- (CGSize)sizeFromNSString:(NSString *)str font:(UIFont *)font maxWidth:(CGFloat)maxWidth{
    NSDictionary *dic = @{NSFontAttributeName:font};
    CGSize nameSize = [str boundingRectWithSize:CGSizeMake(maxWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return nameSize;
}

//重写set方法  相当于当XX.soundDetail = xx的时候   调用该方法
- (void)setSoundDetail:(InSoundDetail *)soundDetail {
    
    _soundDetail = soundDetail;
    
    CGFloat marginX = 10;
    
    CGFloat marginY = 10;
    
    CGFloat textViewX = marginX;
    
    CGFloat textViewY = marginY;
    
    CGFloat textViewW = [[UIScreen mainScreen] bounds].size.width - 2 * marginX;
    CGSize textSize = [self sizeFromNSString:self.soundDetail.sound_info font:kTextFont maxWidth:textViewW];
    
    self.textViewLabelFrame = (CGRect){{textViewX ,textViewY },textSize};
    
    if (self.soundDetail.sound_info) {
        
        self.cellHeight = CGRectGetMaxY(self.textViewLabelFrame) + marginY;
    }else {
        self.cellHeight = 0;
    }
}

@end
